package cn.xerllent.common.service.mapper;


import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import cn.xerllent.common.entity.Msg;
import cn.xerllent.common.entity.vo.MsgUserVo;
import cn.xerllent.common.service.dto.MsgFilter;

@Repository
@Mapper
public interface MsgMapper extends BaseMapper<Msg> {
	
    /**
     * 联表查询返回Msgs
     * */
    @Options(useCache = false)
    @Select("<script>"
    		+ "SELECT m.sendId,m.sender,m.sendtime,m.content,m.type, u.* FROM msg m inner join msg_user u on m.id=u.msgId "
			+ "<where>"
    		+ "<if test = \"uId!=null and uId!=''\" > AND u.uId=#{uId} </if>"
    		+ "<if test = \"blurry!=null and blurry!=''\" >"
    		+ " AND ("
	    		+ "m.content LIKE concat('%', #{blurry}, '%') "
	    		+ "or m.sender LIKE concat('%', #{blurry}, '%') "
    		+ ")"
    		+ "</if>"
    		+ "<if test = \"phase!=null\" > AND u.phase = #{phase} </if>"
    		+ "<if test = \"readed!=null\" > AND u.readed = #{readed} </if>"
    		+ "<if test = \"del!=null\" > AND u.del = #{del} </if>"
    		+ "<if test = \"sendtime !=null and sendtime.size()>1\" > "
    			+ " AND m.sendtime BETWEEN  #{sendtime[0]} and #{sendtime[1]}"
    		+ "</if>"
    		+ "</where>"
    		+ " order by m.id desc"
    		+ "</script>")
    List<MsgUserVo> queryMyMsgs(MsgFilter filter);

}
